<?php 
//File chạy lấy like, cm, share, view của bài
//Chạy 15 ~ 30 phút 1 lần
require_once("../home/config.php");
$arr_link = array();
$arr_user_id = array();
$db_view_ip = new db_query('SELECT DISTINCT vie_share_id,vie_link FROM share_view_ip');
while($row = mysql_fetch_assoc($db_view_ip->result)) {
    $arr_link[$row['vie_share_id']] = $row['vie_link'];
}
$arr_statistics = get_fb_statistics($arr_link);
foreach($arr_statistics as $key=>$value) {
    $db_select = new db_query('SELECT sta_share_id FROM share_statistics WHERE sta_share_id = '.$key);
    if(mysql_num_rows($db_select->result) == 1) {
        $db_update = new db_execute('UPDATE share_statistics 
                                        SET sta_like = '.$value['total_count'].', 
                                            sta_comment = '.$value['commentsbox_count'].', 
                                            sta_share = '.$value['share_count'].'
                                        WHERE sta_share_id = '.$key.'');
    }else {
        $db_insert = new db_execute('INSERT INTO share_statistics
                                                (sta_share_id,
                                                sta_like,
                                                sta_comment,
                                                sta_share) 
                                        VALUES('.$key.',
                                                '.$value['total_count'].',
                                                '.$value['commentsbox_count'].',
                                                '.$value['share_count'].')');
    }
    
    $db_count_view = new db_count('SELECT count(*) as count FROM share_view_ip WHERE vie_share_id = '.$key);
    $count_view = $db_count_view->total;unset($db_count_view);
    $db_insert_view = new db_execute('UPDATE share_statistics 
                                        SET sta_view = sta_view + '.$count_view.'
                                        WHERE sta_share_id = '.$key.'');
    
    $db_delete = new db_execute('DELETE FROM share_view_ip WHERE vie_share_id = '.$key);
    
}
?>